/* JavaLog - package tracker 
 * 
 * Copyright (C) 2009  Allyson Lima, Diego Pedro, Victor Freire
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software 
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this 
 * program.  If not, see <http://www.gnu.org/licenses/>.
 */

package br.edu.ufcg.ccc.javalog.view;

import java.util.ArrayList;
import java.util.List;

import br.edu.ufcg.ccc.javalog.controller.HeadquartersController;
import br.edu.ufcg.ccc.javalog.model.Data;

/**
 * MainView class.
 * @author Allyson Lima, Diego Pedro, Victor Freire
 * @version 11/10/09
 */
public class MainView implements View {
	
	private static final List<String> MENU_OPTIONS = new ArrayList<String>();
	
	private HeadquartersController headquartersController = new HeadquartersController(Data.getHeadquarters());
	
	static 
	{
		MENU_OPTIONS.add("Adicionar franquia");
		MENU_OPTIONS.add("Ver franquia");
		MENU_OPTIONS.add("Modificar o nome de uma franquia");
		MENU_OPTIONS.add("Modificar o local de uma franquia");
		MENU_OPTIONS.add("Modificar dados do aeroporto de uma franquia");
		MENU_OPTIONS.add("Deletar franquia");
	}
		
	/**
	 * Displays the text menu.
	 */
	private static void displayMenu() {
		System.out.printf("%nJavaLog - Rastreador de Pacotes by Allyson Lima, Diego Pedro and Victor Freire%n%n");
		
		for(int i = 0; i < MENU_OPTIONS.size(); ++i) {
			System.out.printf("%d. %s%n", i + 1, MENU_OPTIONS.get(i));
		}
		System.out.printf("0. Exit%n");
	}
	
	
	
	/**
	 * Main Entry point for JavaLog.
	 */
	public boolean view() {
		displayMenu();
		int cmd = ViewUtil.getInt("%nSelecione uma opcao: ", 0, MENU_OPTIONS.size());

		switch(cmd) {
		case 0:
			return false;
				
		case 1:
			headquartersController.addFranchise();
			break;

		case 2:
			headquartersController.seeFranchise();
			break;
					
		case 3:
			headquartersController.changeFranchiseName();					
			break;
					
		case 4:
			headquartersController.changeFranchiseAddress();					
			break;
					
		case 5:
			headquartersController.changeFranchiseAirport();
			break;
					
		case 6:
			headquartersController.removeFranchise();
			break;

		default:
			System.err.println("Opcao nao reconhecida!");
			break;
		}

		System.out.printf("%nObrigado por usar JavaLog!%n");
		
		return true;
	}

}

